package com.chaos.auth.config.userdetails;

import com.chaos.auth.api.enums.GrantTypeEnums;
import com.chaos.auth.config.exception.PhoneNotFoundException;
import com.chaos.auth.config.userdetails.base.UserDetailsExtService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.DisabledException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

/**
 * @author Jacky
 */
@Slf4j
@Component
public class UserByPhoneDetailsService implements UserDetailsExtService {

//    @Resource
//    private UserFeign userFeign;

    @Override
    public UserDetails loadUserByPhone(String phone, Long tenantId) throws PhoneNotFoundException {
//        UserDto queryData = UserDto.builder().phone(phone).build();
//        //queryData.setTenantId(tenantId);
//        List<UserDto> userInfoDatas = userFeign.list(queryData);
//        UserDto userData = null;
//        if (ObjectUtil.isEmpty(userInfoDatas)) {
//            //userInfoData = (TUserData) register(registerDto);
//        } else {
//            userData = userInfoDatas.get(0);
//        }
        AppUserDetails userDetails = new AppUserDetails(null);
        if (!userDetails.isEnabled()) {
            throw new DisabledException("该账户已被禁用!");
        }
        userDetails.setAuthenticationIdentity(GrantTypeEnums.APP_PHONE.getCode());
        return userDetails;

    }


}
